/**
 * name:        首页专用头部
 * author:      wuwq & lyj
 * Time:        18/01/26
 * Copyright:   bgemall.com
 */

$(function(){
//  $('head').append('<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">');
    // 网站顶部内容 start 
    var t=''; 
    t+='<div class="mod_head_wrap">';
    t+='<a class="mod_logo" href="/index.html"></a>';
    t+='<div class="mod_search">'; 
    t+='<form class="search_form" action="">'; 
    t+='<div class="search_wrap">'; 
    t+='<input class="search_input" type="text" placeholder="请输入关键词">'; 
    t+='</div>'; 
    t+='</form>'; 
    t+='<div class="search_btn">'; 
    t+='<i class="search_btn_icon"></i>'; 
    t+='</div>'; 
    t+='<ul class="hot_search" id="hotSearch">'; 
    t+='</ul>'; 
    t+='</div>'; 
    t+='<div class="mod_info">'; 
    t+='<a class="shopping_cart" href="../src/cart/cart.html"><i class="cart_icon"></i><span>购物车</span><em></em></a>'; 
//  t+='<a class="kefu_line" href="javascript:0;"><i class="tel_icon"></i><span>0592-6031-095</span></a>'; 
    t+='</div>'; 
    t+='</div>'; 
    // 网站顶部内容 end
    // 网站顶部菜单导航 start
    var nav=''; 
    nav+='<nav class="mod_nav">'; 
    nav+='<div class="mod_nav_wrap">'; 
    
    
    nav+='<div class="mod_serve">'; 
    nav+='<div class="mod_submenu">';
    
    nav+='<div style="font-weight:bold;">全部服务</div>'; 
    
    nav+='<div class="mod_submenu" style="position: relative;">'; 
    nav+='<ul class="mod_menu_list">'; 
    
    nav+='<li class="mod_submenu" id="subMenuTop" style="width:200px;">'; 
//  nav+='<div class="mod_subment_tit"><i class="submenu_icon submenu_icon_01"></i><a href="javascript:;">品类采购</a></div>'; 
     nav+='<ul class="mod_submenu_top" id="mod_submenu_top">'; 
    nav+='<li class="nav_1"><a href="./src/type/type_list.html?categoryId=4136&parentId=0" target="_blank">水果蔬菜<img src="./img/base/triangle_right_01.png"/></a></li>'
    nav+='<li class="nav_2"><a href="./src/type/type_list.html?categoryId=4137&parentId=0" target="_blank">粮油干货<img src="./img/base/triangle_right_01.png"/></a></li>'
    nav+='<li class="nav_3"><a href="./src/type/type_list.html?categoryId=4138&parentId=0" target="_blank">畜牧水产<img src="./img/base/triangle_right_01.png"/></a></li>'
    nav+='<li class="nav_4"><a href="./src/type/type_list.html?categoryId=4139&parentId=0" target="_blank">农副加工<img src="./img/base/triangle_right_01.png"/></a></li>'
    nav+='<li class="nav_5"><a href="./src/type/type_list.html?categoryId=4105&parentId=0" target="_blank">粮油副食<img src="./img/base/triangle_right_01.png"/></a></li>'
    nav+='<li class="nav_6"><a href="./src/type/type_list.html?categoryId=4106&parentId=0" target="_blank">零食干果<img src="./img/base/triangle_right_01.png"/></a></li>'
    nav+='<li class="nav_7"><a href="./src/type/type_list.html?categoryId=4107&parentId=0" target="_blank">茗茶名酒<img src="./img/base/triangle_right_01.png"/></a></li>'
    nav+='<li class="nav_8"><a href="./src/type/type_list.html?categoryId=4108&parentId=0" target="_blank">3C小家电<img src="./img/base/triangle_right_01.png"/></a></li>'
    nav+='<li class="nav_9"><a href="./src/type/type_list.html?categoryId=4109&parentId=0" target="_blank">家居家纺<img src="./img/base/triangle_right_01.png"/></a></li>'
    nav+='<li class="nav_10"><a href="./src/type/type_list.html?categoryId=4110&parentId=0" target="_blank">商务礼品<img src="./img/base/triangle_right_01.png"/></a></li>'
    nav+='</ul>'; 
//  nav+='<ul class="mod_submenu_top" id="mod_submenu_top">';
//  nav+='<li class="nav_1"><i class="nav_img1"></i><a href="./src/type/type_list.html?categoryId=4136&parentId=0" target="_blank">水果蔬菜</a></li>'
//  nav+='<li class="nav_2"><i class="nav_img2"></i><a href="./src/type/type_list.html?categoryId=4137&parentId=0" target="_blank">粮油干货</a></li>'
//  nav+='<li class="nav_3"><i class="nav_img3"></i><a href="./src/type/type_list.html?categoryId=4138&parentId=0" target="_blank">畜牧水产</a></li>'
//  nav+='<li class="nav_4"><i class="nav_img4"></i><a href="./src/type/type_list.html?categoryId=4139&parentId=0" target="_blank">农副加工</a></li>'
//  nav+='<li class="nav_5"><i class="nav_img5"></i><a href="./src/type/type_list.html?categoryId=4105&parentId=0" target="_blank">粮油副食</a></li>'
//  nav+='<li class="nav_6"><i class="nav_img6"></i><a href="./src/type/type_list.html?categoryId=4106&parentId=0" target="_blank">零食干果</a></li>'
//  nav+='<li class="nav_7"><i class="nav_img7"></i><a href="./src/type/type_list.html?categoryId=4107&parentId=0" target="_blank">茗茶名酒</a></li>'
//  nav+='<li class="nav_8"><i class="nav_img8"></i><a href="./src/type/type_list.html?categoryId=4108&parentId=0" target="_blank">3C小家电</a></li>'
//  nav+='<li class="nav_9"><i class="nav_img9"></i><a href="./src/type/type_list.html?categoryId=4109&parentId=0" target="_blank">家居家纺</a></li>'
//  nav+='<li class="nav_10"><i class="nav_img10"></i><a href="./src/type/type_list.html?categoryId=4110&parentId=0" target="_blank">商务礼品</a></li>'
//  nav+='</ul>'; 
    nav+='</li>'; 
    
//  nav+='<li class="mod_submenu" id="subMenuTop" style="width:200px;">'; 
//  nav+='<div class="mod_subment_tit"><i class="submenu_icon submenu_icon_01"></i><a href="javascript:;">品类采购</a></div>'; 
//  nav+='<ul class="mod_submenu_top" id="mod_submenu_top">'; 
//  nav+='</ul>'; 
//  nav+='</li>'; 
//  
//  nav+='<li class="mod_submenu">'; 
//  nav+='<div class="mod_subment_tit"><i class="submenu_icon submenu_icon_02"></i><a href="javascript:;" class="kfing">场景定制</a></div>'; 
//  nav+='<dl>'; 
//  nav+='<dd>'; 
//  nav+='<a href="javascript:;" class="kfing">博饼礼包</a>'; 
//  nav+='<a href="javascript:;" class="kfing">年终礼包</a>'; 
//  nav+='<a href="javascript:;" class="kfing">中秋礼包</a>'; 
//  nav+='<a href="javascript:;" class="kfing">五一礼包</a>'; 
//  nav+='</dd>'; 
//  nav+='</dl>'; 
//  nav+='</li>'; 
    
//  nav+='<li class="mod_submenu">';
//  nav+='<div class="mod_subment_tit"><i class="submenu_icon submenu_icon_03"></i><a href="/src/case/case.html?type=1" target="_blank">特色出行</a></div>';
//  nav+='<dl>'; 
//  nav+='<dd>'; 
//  nav+='<a href="../src/case/case_detail.html?T=1&Id=275" target="_blank">云顶温泉</a>'; 
//  nav+='<a href="../src/case/case_detail.html?T=1&Id=278" target="_blank">长泰漂流</a>'; 
//  nav+='<a href="../src/case/case_detail.html?T=1&Id=268" target="_blank">南靖土楼</a>'; 
//  nav+='<a href="../src/case/case_detail.html?T=1&Id=279" target="_blank">志闽团建</a>'; 
//  nav+='</dd>'; 
//  nav+='</dl>'; 
//  nav+='</li>'; 
//  
//  nav+='<li class="mod_submenu">'; 
//  nav+='<div class="mod_subment_tit"><i class="submenu_icon submenu_icon_04"></i><a href="javascript:;" class="kfing">企业定制</a></div>'; 
//  nav+='<dl>'; 
//  nav+='<dd class="fw">'; 
//  nav+='<a href="../src/service/purchase.html?type=1">采购需求</a>'; 
//  nav+='<a href="../src/service/purchase.html?type=2">服务需求</a>'; 
//  nav+='</dd>'; 
//  nav+='</dl>'; 
//  nav+='</li>'; 
    
    nav+='</ul>'; 
//  右侧详情层
//  nav+='<div class="submenu_pop" id="submenu_pop">'; 
//  nav+='<ul class="pop_top" id="pop_top"></ul>'; 
//  nav+='<ul class="pop_list" id="pop_list"></ul>'; 
//  nav+='</div>'; 
    
    nav+='</div>'; 
    
    nav+='</div>'; 
    nav+='</div>'; 


    nav+='<ul class="mod_menu">'; 
    nav+='<li><a href="/index.html">首页</a></li>'; 
//  nav+='<li><a href="./src/scarebuy/scarebuy.html" target="_blank">限时抢购</a></li>'; 
// 	nav+='<li><a href="./src/case/case.html?type=0" target="_blank">成功案例</a></li>'
// nav+='<li><a href="./src/about/about_us.html">关于购吧</a></li>'
    
    nav+='</ul>'; 
    
    
    
//  nav+='<div class="mod_login">'; 
//  nav+='<div class="yes_or_no"><a class="login" href="../src/login/login.html?type=2">登录</a>'; 
//  nav+='<span>|</span>'; 
//  nav+='<a class="register" href="../src/login/register.html">注册</a></div>'; 
//  nav+='</div>'; 
    
    
    nav+='</div>'; 
    nav+='</nav>'; 
    // 网站顶部菜单导航 end 
    var hover=''; 

    var scri=''; // 左边菜单的一级菜单 
    var scri2=''; // 弹出窗 顶部的四个菜单 
    var scri3=''; // 弹出窗 主菜单 一级菜单 
    var scri4=''; // 弹出窗 主菜单 二级菜单 
    var scri6=''; // 热门搜索 
    // 左边菜单的一级菜单 start 
    scri+='<script id="tpl" type="text/html">'; 
    scri+='{{ for(var i = 0; i < list.length; i++) { }}'; 
    scri+='<li><a href="/src/type/type_list.html?categoryId={{=list[i].categoryId}}&parentId={{=list[i].parentId}}" target="_blank">{{=list[i].name}}</a></li>'; 
    scri+='{{ } }}'; 
    scri+='</script>'; 
    // 弹出窗 顶部的四个菜单 start 
    scri2+='<script id="tplTwo" type="text/html">'; 
    scri2+='{{ for(var i = 0; i < listTwo.length; i++) { }}'; 
    scri2+='<li><a href="/src/type/type_list.html?categoryId={{=listTwo[i].categoryId}}&parentId={{=listTwo[i].parentId}}" target="_blank">{{=listTwo[i].name}}&nbsp;&nbsp;></a></li>'; 
    scri2+='{{ } }}'; 
    scri2+='</script>'; 
    // 弹出窗 主菜单 一级菜单 start 
    scri3+='<script id="tplChild" type="text/html">'; 
    scri3+='{{ for(var a = 0; a < tplChildList.length; a++) { }}'; 
    scri3+='<li>'; 
    scri3+='<a class="menu" href="/src/type/type_list.html?categoryId={{=tplChildList[a].categoryId}}&parentId={{=tplChildList[a].parentId}}" target="_blank">'; 
    scri3+='{{=tplChildList[a].name}}'; 
    scri3+='</a>'; 
    scri3+='<ul class="sub_menu_list" id="menu{{=tplChildList[a].index}}">'; 
    scri3+='</ul>'; 
    scri3+='</li>'; 
    scri3+='{{ } }}'; 
    scri3+='</script>'; 
    // 弹出窗 主菜单 二级菜单 start 
    scri4+='<script id="subMenuTpl" type="text/html">'; 
    scri4+='{{ for(var i = 0; i < subMenuList.length; i++) { }}'; 
    scri4+='<li>'; 
    scri4+='<a href="../src/type/type_list.html?categoryId={{=subMenuList[i].categoryId}}&parentId={{=subMenuList[i].parentId}}" target="_blank">'; 
    scri4+='{{=subMenuList[i].childName}}'; 
    scri4+='</a>'; 
    scri4+='</li>'; 
    scri4+='{{ } }}'; 
    scri4+='</script>'; 
    // 热门搜索 start 
    scri6+='<script id="hotSearchTpl" type="text/html">'; 
    scri6+='{{ for(var i = 0; i < hotSearchList.length; i++) { }}'; 
    scri6+='<li>'; 
    scri6+='<a href="../src/search/search_list.html?keyword={{=hotSearchList[i].name}}" target="_blank">'; 
    scri6+='{{=hotSearchList[i].name}}'; 
    scri6+='</a>'; 
    scri6+='</li>'; 
    scri6+='{{ } }}'; 
    scri6+='</script>'; 

    $('.mod_head').append(t); // 添加顶部到网站
    $('.mod_head').after(nav);  // 添加菜单
    $('body').append(hover); //
    $('body').append(scri); // 左边菜单的一级菜单 
    $('body').append(scri2); // 弹出窗 顶部的四个菜单 
    $('body').append(scri3); // 弹出窗 主菜单 一级菜单 
    $('body').append(scri4); // 弹出窗 主菜单 二级菜单 start 
    $('body').append(scri6); // 热门搜索 

    function s(){
        var searchIup = $(".search_input").val(); // 获取搜索框的值
        // 去除空格; 
        function removeAllSpace(str) { 
            return str.replace(/\s+/g, ""); 
        } 
        // 查找字符串; 
        function countStr(str, strSplit) { 
            return str.split(strSplit).length - 1; 
        } 
        if(removeAllSpace(searchIup)==""){ 
            tc("请输入关键词"); 
            $(".search_input").val('') 
            return; 
        }else{ 
            var new_href = window.location.href; 
            if(countStr(new_href,'src')!= '1'){ 
                var url = "/src/search/search_list.html?keyword="+searchIup; 
                window.location.href=url; 
            }else{ 
                window.location.href="/src/search/search_list.html?keyword="+searchIup; 
            } 
        } 
    } 
    // 确认搜索; 
    $(".search_btn").click(function(){ 
        s(); 
    }); 
    // 回车确定搜索;
    $(".search_input").keydown(function (e) { 
        if (e.which == 13) { 
            $('.search_btn').trigger("click"); 
            return false; 
        } 
    }); 
    // 首页左侧类目; 
    $.ajax({ 
        type:'post', 
        url:new_url+'shop/index/getCategoryList', 
        dataType:'json', 
        success:function(response){ 
            getCategoryList_one(response);      // 一级菜单; 
            getCategoryList_two(response);      // 弹出窗 主菜单 二级菜单; 
        } 
    }); 
    // 一级菜单; 
    function getCategoryList_one(response){ 
        // 一级菜单; 
//      var tpl = $('#tpl').html(); 
//      for (var i=0; i<4; i++){ 
//          var t=template( 
//              tpl, { 
//                  list: [{ 
//                      name:response.data[i].name, 
//                      categoryId:response.data[i].categoryId, 
//                      parentId:response.data[i].parentId 
//                  }] 
//              } 
//          ); 
//          $('#mod_submenu_top').append(t); 
//      } 
			for (var i=0; i<response.data.length; i++){ 
            var t=template( 
                tpl, { 
                    list: [{ 
                        name:response.data[i].name, 
                        categoryId:response.data[i].categoryId, 
                        parentId:response.data[i].parentId 
                    }] 
                } 
            ); 
//          $('#mod_submenu_top').append(t); 
        } 
		
        // 弹出窗 顶部的四个菜单; 
        var tplTwo = $('#tplTwo').html(); 
        for (var i=0; i<4; i++){ 
            var tTwo=template( 
                tplTwo, { 
                    listTwo: [{ 
                        name:response.data[i].name, 
                        categoryId:response.data[i].categoryId, 
                        parentId:response.data[i].parentId 
                    }] 
                } 
            ); 
            $('.pop_top').append(tTwo); 
        }
        // 弹出窗 主菜单 一级菜单;
        var tplChild = $('#tplChild').html(); 
        for (var k=0; k<response.data.length; k++){ 
            var tplChildCont=template( 
                tplChild, { 
                    tplChildList: [{ 
                        index:k+1, 
                        name:response.data[k].name, 
                        categoryId:response.data[k].categoryId, 
                        parentId:response.data[k].parentId 
                    }] 
                } 
            ); 
            $('#pop_list').append(tplChildCont); 
        } 
    } 
    // 弹出窗 主菜单 二级菜单; 
    function getCategoryList_two(response){ 
        // 弹出窗 主菜单 二级菜单; 
        var subMenuTpl = $("#subMenuTpl").html(); 
        for (var s=0; s<response.data.length; s++){ 
            for(var j=0;j<response.data[s].childCategoryList.length;j++){ 
                var subMenucont=template( 
                    subMenuTpl, { 
                        subMenuList: [{ 
                            childName:response.data[s].childCategoryList[j].name, 
                            categoryId:response.data[s].childCategoryList[j].categoryId, 
                            parentId:response.data[s].childCategoryList[j].parentId 
                        }] 
                    } 
                ); 
                var k = "#menu"+(s+1); 
                $(k).append(subMenucont); 
            } 
        } 
    } 
    // 正在开发; 
    $(".kfing").click(function(){ 
        kf(); 
    }); 
    // 热门搜索; 
    $.ajax({ 
        type:'post', 
        url:new_url+'shop/search/getHotSearch', 
        dataType:'json', 
        success:function(e){ 
            var strs=e.data.value.split(","); 
            var hotSearch = new Array(); 
            var hotSearchTpl = $('#hotSearchTpl').html(); 
            for(var i in strs){ 
                var hotSearchCont=template( 
                    hotSearchTpl, { 
                        hotSearchList: [{ 
                            name:strs[i] 
                        }] 
                    } 
                ); 
                $('#hotSearch').append(hotSearchCont);  
            } 
        } 
    }); 
    // 鼠标移入/移出，显示/隐藏菜单
    $('#subMenuTop, #submenu_pop').mouseover(function(){ 
        $("#subMenuTop").addClass('active'); 
        $('#submenu_pop').css("display","block"); 
        $('#mod_submenu_top').css('border-bottom','rgba(255,255,255,.9) solid 1px'); 
    }); 
    $('#subMenuTop, #submenu_pop').mouseout(function(){ 
        $("#subMenuTop").removeClass('active'); 
        $('#submenu_pop').css("display","none"); 
        $('#mod_submenu_top').css('border-bottom','rgba(204,204,204,0.5) solid 1px'); 
    }); 
}); 
// 判断是否登录; 
$(function(){
    if($.cookie('user')!=''&&$.cookie('user')!=null){ 
        // 已登录过的; 
    }else{ 
        // 未登录状态，执行的事件; 
        // setTimeout(function(){ 
        //     $('.fw').last().find('a').attr('href','/login/login.html?type=2'); 
        // },300); 
        $('.shopping_cart').attr('href','javascript:0;'); 
        // 点击购物车，先提示'请登录'，然后再跳转到登录页面
        $('.shopping_cart').click(function(){ 
            tc('请登录'); 
            setTimeout(function(){ 
                window.location.href='/src/login/login.html?type=2'; 
            },300); 
        }); 
    } 
}); 